import 'package:flutter/material.dart';
import 'package:global_time/pages/home.dart';
import 'package:global_time/pages/select_time.dart';
import 'package:global_time/router/context_extension.dart';
import 'package:global_time/service/one_sentence.dart';



class Loading extends StatefulWidget {
  const Loading({super.key});

  @override
  State<Loading> createState() => _LoadingState();
}

class _LoadingState extends State<Loading> {
  OneSentence instance = OneSentence();
  late String? sentence = '点一下就会有一句话，点一下试试吧';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Center(
            child: Text("加载页面")
        ),
      ),
      body: Column(
        crossAxisAlignment:  CrossAxisAlignment.center,
        children: [
          Divider(height: 50,color: Theme.of(context).colorScheme.primary,),
          Card(
            color: Theme.of(context).colorScheme.primaryContainer,
            margin: EdgeInsets.all(16), // 设置卡片的外边距
            child: Padding(
              padding: EdgeInsets.all(16), // 设置卡片内部的内边距
              child: Column(
                children: [
                  SizedBox(height: 10),
                  RichText(
                    text: TextSpan(
                      children: [
                        WidgetSpan(
                          child: SizedBox(width: 40), // 通过SizedBox的宽度来模拟首行缩进
                        ),
                        TextSpan(
                          text: sentence!,
                          style: TextStyle(
                            fontSize: 20,
                          ),
                        ),
                      ],
                    ),
                  ),
                  TextButton.icon(
                    onPressed: () async {
                      String? sentenceResult = await instance.getSentence();
                      if (sentenceResult != null) {
                        setState(() {
                          sentence = sentenceResult;
                        });
                      }
                    },
                    label: Text("再来一句"),
                    icon: Icon(Icons.generating_tokens_outlined),
                  ),
                ],
              ),
            ),
          ),
          SizedBox(height: 20,),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              TextButton.icon(
                onPressed: (){
                  context.routeTo(Home);
                },
                label: Text("进入首页"),
                icon: Icon(Icons.home_max),
              ),
              TextButton.icon(
                onPressed: (){
                  context.routeTo(SelectTime);
                },
                label: Text("进入选择页"),
                icon: Icon(Icons.select_all_sharp),
              ),
            ],
          )
        ],
      ),
    );
  }
}
